package com.ktwlsoft.archivemanage.domain.business.repositoryService;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ktwlsoft.archivemanage.domain.dao.entity.Question;
import com.ktwlsoft.archivemanage.domain.dao.repository.QuestionMapper;
import com.ktwlsoft.archivemanage.payload.question.QuestionPageRequest;
import lombok.Getter;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author JokerMo
 * @version 1.0
 * @date 2019/12/12 14:13
 */
@Service
public class QuestionRepositoryService {
    @Getter
    private final QuestionMapper questionMapper;

    public QuestionRepositoryService(QuestionMapper questionMapper) {
        this.questionMapper = questionMapper;
    }
    /**
     * 查询分页
     * @param request
     * @return PageInfo<Question>
     */
    public PageInfo<Question> findPage(QuestionPageRequest request) {
        PageHelper.startPage(request.getPn(),request.getPageSize());
        PageInfo<Question> pageInfo = new PageInfo<Question>(questionMapper.findPage(request));
        return pageInfo;
    }
    /**
     * 根据ID查询信息
     * @param id	主键
     * @return MessageManage
     */
    public Question getById(Long id){
        return questionMapper.selectByPrimaryKey(id);
    }

    /**
     * 新增
     * @param question question
     * @return int
     */
    public int insert(Question question){
        return questionMapper.insert(question);
    }

    /**
     * 修改
     * @param question question
     * @return int
     */
    public int update(Question question){
        return questionMapper.updateByPrimaryKey(question);
    }

    /**
     * 根据id删除信息
     * @param id id
     * @return int
     */
    public int deleteById(Long id){
        return questionMapper.deleteByPrimaryKey(id);
    }
}
